x_list = [24, 26, 28, 30]
y_list = [1.888175, 1.918645, 1.947294, 1.961009]


# 拉格朗日插值
def lagrange(target):
    res = 0
    for i in range(len(x_list)):
        temp = y_list[i]
        for j in range(len(y_list)):
            if i != j:
                temp = temp * (target - x_list[j])
                temp = temp / (x_list[i] - x_list[j])
        res += temp
    return res


def main():
    target_list = [25, 27, 29]
    for target in target_list:
        result = lagrange(target)
        print("插值点(x, y) = (", target, ",", result, ")")


if __name__ == '__main__':
    main()
